package com.jrh.biz.mall;

import java.util.List;

import com.jrh.common.condition.Precondition;
import com.jrh.dal.MallDao;
import com.jrh.domain.entity.Mall;

/**
 * 类MallServiceImpl.java的实现描述：卖场服务
 * 
 * @author mmy 2012-7-24 上午8:15:49
 */
public class MallServiceImpl implements MallService {

	MallDao mallDao;

	@Override
	public Mall loadById(Long id) {
		Precondition.checkNotNull(id, "id can not null!");
		return mallDao.load(id);
	}

	@Override
	public boolean addMall(Mall mall) {
		Precondition.checkNotNull(mall, "mall can not null!");
		Precondition.checkNotBlank(mall.getPrimaryName(),
				"primaryName can not blank!");
		Precondition.checkNotBlank(mall.getSecondaryName(),
				"secondaryName can not blank!");
		try {
			mallDao.create(mall);
			return Boolean.TRUE;
		} catch (Exception e) {
			// TODO 记录日志
			e.printStackTrace();
		}
		return Boolean.FALSE;
	}

	@Override
	public boolean updateMall(Mall mall) {
		Precondition.checkNotNull(mall, "mall can not null!");
		Precondition.checkNotNull(mall.getId(), "id can not null!");
		Precondition.checkNotBlank(mall.getPrimaryName(),
				"primaryName can not blank!");
		Precondition.checkNotBlank(mall.getSecondaryName(),
				"secondaryName can not blank!");
		boolean isSuccess = Boolean.FALSE;
		try {
			isSuccess = mallDao.update(mall);
			if (isSuccess)
				return Boolean.TRUE;
		} catch (Exception e) {
			// TODO 记录日志
		}
		return Boolean.FALSE;
	}

	@Override
	public boolean deleteMallBy(Long id) {
		Precondition.checkNotNull(id, "id can not null!");
		// TODO 检索与卖场关联表,存在则抛异常
		try {
			mallDao.delete(id);
		} catch (Exception e) {
			// TODO 记录日志
			e.printStackTrace();
			return Boolean.FALSE;
		}
		return Boolean.TRUE;
	}

	@Override
	public List<Mall> findAll() {
		return mallDao.findAllMall();
	}

	public void setMallDao(MallDao mallDao) {
		this.mallDao = mallDao;
	}

}
